package com.ynny.dao;

import com.ynny.bean.Score;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public class ScoreDaoImpl implements ScoreDao{
    @Autowired
    JdbcTemplate jdbcTemplate;



    @Override
    public List<Score> selectAll() {
        String sql = "select * from score";
        List<Score> list = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(Score.class));
        return list;

    }

    @Override
    public Score getScore(String number) {
        String sql = "select * from score where number = ?";
        Score score = jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<>(Score.class),number);
        return score;

    }

    @Override
    public int insertScore(String number, Double chinese, Double english, Double math) {
        String sql = "insert into score(number,chinese,english,math) values(?,?,?,?)";
        int i = jdbcTemplate.update(sql,number,chinese,english,math);
        return i;

    }

    @Override
    public int updateScore(String number, Double chinese, Double english, Double math) {
        String sql = "update score set chinese = ?,english = ?,math = ? where number = ?";
        int i = jdbcTemplate.update(sql,chinese,english,math,number);
        return i;

    }
}
